package com.cx.mall.user.controller;

import com.cx.mall.common.util.ResponseVO;
import com.cx.mall.user.entity.UserInfo;
import com.cx.mall.user.service.IUserInfoService;
import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserInfoController {
    @Autowired
    private IUserInfoService userInfoService;
    /**
     * 用户注册
     */
    @PostMapping("/register")
    public ResponseVO register(@RequestBody UserInfo userInfo) {
        //密码加密
        String hashpw = BCrypt.hashpw(userInfo.getPassword(), BCrypt.gensalt());
        userInfo.setPassword(hashpw);
        //调用 service
        userInfoService.save(userInfo);
        return ResponseVO.success();
    }
    /**
     * 修改用户信息
     */
    @PutMapping("/update")
    public ResponseVO update(@RequestBody UserInfo userInfo){
        //调用service层进行修改
        userInfoService.updateById(userInfo);
        return ResponseVO.success();
    }

}
